import os
from multiprocessing import Process
from time import sleep

def task1(s,name):
    while True:
        sleep(s)
        print('-------这是任务1--------',os.getpid(),'-----',os.getppid(),name)

def task2(s,name):
    while True:
        sleep(s)
        print('-------这是任务2--------',os.getpid(),'-----',os.getppid(),name)

number = 1
if __name__ == '__main__':
    # 子进程
    p = Process(target=task1,name = '任务1',args=(1,'aa'))
    p.start()
    print(p.name)
    p2 = Process(target=task2,name='任务2',args=(2,'bb'))
    p2.start()
    print(p2.name)

    while True:
        number += 1
        sleep(0.2)
        if number == 100:
            p.terminate()
            p2.terminate()
            break
        else:
            print('--->number',number)

    print('-------------')
    print('*************')